package com.luych.toolbox.docker.service.sdk.image.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class DockerImagesPullResult {

    @JsonProperty("id")
    private String id;

    @JsonProperty("status")
    private String status;

    @JsonProperty("progress")
    private String progress;

    @JsonProperty("progressDetail")
    private ProgressDetail progressDetail;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public ProgressDetail getProgressDetail() {
        return progressDetail;
    }

    public void setProgressDetail(ProgressDetail progressDetail) {
        this.progressDetail = progressDetail;
    }

    public String getProgress() {
        return progress;
    }

    public void setProgress(String progress) {
        this.progress = progress;
    }

    @Override
    public String toString() {
        String string = (id == null ? "" : (id + ": ")) + (status == null ? "" : status);
        if (progressDetail != null) {
            string += " " + progressDetail.toString();
        }
        return string;
    }

    public static class ProgressDetail {

        @JsonProperty("total")
        private Long total;

        @JsonProperty("current")
        private Long current;

        public Long getTotal() {
            return total;
        }

        public void setTotal(Long total) {
            this.total = total;
        }

        public Long getCurrent() {
            return current;
        }

        public void setCurrent(Long current) {
            this.current = current;
        }

        @Override
        public String toString() {
            if (current == null || total == null) return "";
            float percent = Math.round(100000F * current / total) / 1000F;
            return percent + "%(" + current + "/" + total + ")";
        }
    }
}
